package cn.wolfcode.shop.web.advice;

import cn.wolfcode.shop.common.CommonControllerAdvice;
import cn.wolfcode.shop.common.Result;
import cn.wolfcode.shop.web.result.MemberServerCodeMsg;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
public class MemberServerControllerAdvice extends CommonControllerAdvice{
    // 统一处理MemberServer的特有异常
    @ExceptionHandler(BindException.class)
    @ResponseBody
    public Result handlerBindException(BindException ex){
        String msg = ex.getAllErrors().get(0).getDefaultMessage();
        return Result.error(MemberServerCodeMsg.PARAM_ERROR.fillArgs(msg));
    }
}
